import request from "@/utils/request";

import type { GetTrademarkListApiResponse, TrademarkItem, TrademarkList } from "./model/trademarkModel";

// 使用枚举定义接口地址
enum Api {
  getTrademarkList = "/admin/product/baseTrademark",
  getAllTrademarkList = "/admin/product/baseTrademark/getTrademarkList",
  saveTrademark = "/admin/product/baseTrademark/save",
  updateTrademark = "/admin/product/baseTrademark/update",
  removeTrademark = "/admin/product/baseTrademark/remove",
}

// 获取品牌分页列表
export const getTrademarkListApi = (page: number, limit: number) => {
  /*
    get<T = any, R = AxiosResponse<T>, D = any>(url: string, config?: AxiosRequestConfig<D>): Promise<R>;
      get是一个函数，接受两个参数（url, config）, 返回值类型是Promise

    get的第二个泛型参数类型就会作为响应结果的类型
  */
  return request.get<any, GetTrademarkListApiResponse>(`${Api.getTrademarkList}/${page}/${limit}`);
};

// 获取所有品牌列表
export const getAllTrademarkListApi = () => {
  return request.get<any, TrademarkList>(Api.getAllTrademarkList);
};

// 添加品牌
export const saveTrademarkApi = (tmName: string, logoUrl: string) => {
  // 除了获取请求有返回值，其他修改，添加，删除都没有返回值，都是null
  return request.post<any, null>(Api.saveTrademark, {
    // 请求体参数
    tmName,
    logoUrl,
  });
};

// 修改品牌
export const updateTrademarkApi = (tm: TrademarkItem) => {
  return request.put<any, null>(Api.updateTrademark, tm);
};

// 删除品牌
export const removeTrademarkApi = (id: number) => {
  return request.delete<any, null>(`${Api.removeTrademark}/${id}`);
};
